<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>imagerenderer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_equation_imagerenderer.js.html">imagerenderer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Functions for rendering the equation images.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.ui.equation.ImageRenderer&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line23"></a>goog.require(&#39;goog.dom.classes&#39;);
<a name="line24"></a>goog.require(&#39;goog.string&#39;);
<a name="line25"></a>goog.require(&#39;goog.uri.utils&#39;);
<a name="line26"></a>
<a name="line27"></a>
<a name="line28"></a>/**
<a name="line29"></a> * The server name which renders the equations.
<a name="line30"></a> * We use https as equations may be embedded in https pages
<a name="line31"></a> * and using https prevents mixed content warnings. Note that
<a name="line32"></a> * https equations work only on google.com domains.
<a name="line33"></a> * @type {string}
<a name="line34"></a> * @private
<a name="line35"></a> */
<a name="line36"></a>goog.ui.equation.ImageRenderer.SERVER_NAME_ =
<a name="line37"></a>    &#39;https://www.google.com&#39;;
<a name="line38"></a>
<a name="line39"></a>
<a name="line40"></a>/**
<a name="line41"></a> * The longest equation which may be displayed, in characters.
<a name="line42"></a> * @type {number}
<a name="line43"></a> */
<a name="line44"></a>goog.ui.equation.ImageRenderer.MAX_EQUATION_LENGTH = 200;
<a name="line45"></a>
<a name="line46"></a>
<a name="line47"></a>/**
<a name="line48"></a> * Class to put on our equations IMG elements.
<a name="line49"></a> * @type {string}
<a name="line50"></a> */
<a name="line51"></a>goog.ui.equation.ImageRenderer.EE_IMG_CLASS = &#39;ee_img&#39;;
<a name="line52"></a>
<a name="line53"></a>
<a name="line54"></a>/**
<a name="line55"></a> * Non-standard to put on our equations IMG elements. Useful when classes need
<a name="line56"></a> * to be scrubbed from the user-generated HTML, but non-standard attributes
<a name="line57"></a> * can be white-listed.
<a name="line58"></a> *
<a name="line59"></a> * @type {string}
<a name="line60"></a> */
<a name="line61"></a>goog.ui.equation.ImageRenderer.EE_IMG_ATTR = &#39;eeimg&#39;;
<a name="line62"></a>
<a name="line63"></a>
<a name="line64"></a>/**
<a name="line65"></a> * Vertical alignment for the equations IMG elements.
<a name="line66"></a> * @type {string}
<a name="line67"></a> */
<a name="line68"></a>goog.ui.equation.ImageRenderer.EE_IMG_VERTICAL_ALIGN = &#39;middle&#39;;
<a name="line69"></a>
<a name="line70"></a>
<a name="line71"></a>/**
<a name="line72"></a> * The default background color as used in the img url, which is fully
<a name="line73"></a> * transparent white.
<a name="line74"></a> * @type {string}
<a name="line75"></a> */
<a name="line76"></a>goog.ui.equation.ImageRenderer.BACKGROUND_COLOR = &#39;FFFFFF00&#39;;
<a name="line77"></a>
<a name="line78"></a>
<a name="line79"></a>/**
<a name="line80"></a> * The default foreground color as used in the img url, which is black.
<a name="line81"></a> * @type {string}
<a name="line82"></a> */
<a name="line83"></a>goog.ui.equation.ImageRenderer.FOREGROUND_COLOR = &#39;000000&#39;;
<a name="line84"></a>
<a name="line85"></a>
<a name="line86"></a>/**
<a name="line87"></a> * Class to put on IMG elements to keep the resize property bubble from
<a name="line88"></a> * appearing. This is different from PLACEHOLDER_IMG_CLASS because it&#39;s
<a name="line89"></a> * reasonable in some cases to be able to resize a placeholder (which should
<a name="line90"></a> * be reflected when the placeholder is replaced with the other content).
<a name="line91"></a> * @type {string}
<a name="line92"></a> */
<a name="line93"></a>goog.ui.equation.ImageRenderer.NO_RESIZE_IMG_CLASS =
<a name="line94"></a>    goog.getCssName(&#39;tr_noresize&#39;);
<a name="line95"></a>
<a name="line96"></a>
<a name="line97"></a>/**
<a name="line98"></a> * Returns the equation image src url given the equation.
<a name="line99"></a> * @param {string} equation The equation.
<a name="line100"></a> * @return {string} The equation image src url (empty string in case the
<a name="line101"></a> *   equation was empty).
<a name="line102"></a> */
<a name="line103"></a>goog.ui.equation.ImageRenderer.getImageUrl = function(equation) {
<a name="line104"></a>  if (!equation) {
<a name="line105"></a>    return &#39;&#39;;
<a name="line106"></a>  }
<a name="line107"></a>
<a name="line108"></a>  var url = goog.ui.equation.ImageRenderer.SERVER_NAME_ +
<a name="line109"></a>      &#39;/chart?cht=tx&#39; +
<a name="line110"></a>      &#39;&amp;chf=bg,s,&#39; +
<a name="line111"></a>      goog.ui.equation.ImageRenderer.BACKGROUND_COLOR +
<a name="line112"></a>      &#39;&amp;chco=&#39; +
<a name="line113"></a>      goog.ui.equation.ImageRenderer.FOREGROUND_COLOR +
<a name="line114"></a>      &#39;&amp;chl=&#39; +
<a name="line115"></a>      encodeURIComponent(equation);
<a name="line116"></a>  return url;
<a name="line117"></a>};
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * Returns the equation string src for given image url.
<a name="line122"></a> * @param {string} imageUrl The image url.
<a name="line123"></a> * @return {string?} The equation string, null if imageUrl cannot be parsed.
<a name="line124"></a> */
<a name="line125"></a>goog.ui.equation.ImageRenderer.getEquationFromImageUrl = function(imageUrl) {
<a name="line126"></a>  return goog.uri.utils.getParamValue(imageUrl, &#39;chl&#39;);
<a name="line127"></a>};
<a name="line128"></a>
<a name="line129"></a>
<a name="line130"></a>/**
<a name="line131"></a> * Gets the equation string from the given equation IMG node. Returns empty
<a name="line132"></a> * string if the src attribute of the is not a valid equation url.
<a name="line133"></a> * @param {Element} equationNode The equation IMG element.
<a name="line134"></a> * @return {string} The equation string.
<a name="line135"></a> */
<a name="line136"></a>goog.ui.equation.ImageRenderer.getEquationFromImage = function(equationNode) {
<a name="line137"></a>  var url = equationNode.getAttribute(&#39;src&#39;);
<a name="line138"></a>  if (!url) {
<a name="line139"></a>    // Should never happen.
<a name="line140"></a>    return &#39;&#39;;
<a name="line141"></a>  }
<a name="line142"></a>  return goog.ui.equation.ImageRenderer.getEquationFromImageUrl(
<a name="line143"></a>      url) || &#39;&#39;;
<a name="line144"></a>};
<a name="line145"></a>
<a name="line146"></a>
<a name="line147"></a>/**
<a name="line148"></a> * Checks whether given node is an equation element.
<a name="line149"></a> * @param {Node} node The node to check.
<a name="line150"></a> * @return {boolean} Whether given node is an equation element.
<a name="line151"></a> */
<a name="line152"></a>goog.ui.equation.ImageRenderer.isEquationElement = function(node) {
<a name="line153"></a>  return node.nodeName == goog.dom.TagName.IMG &amp;&amp;
<a name="line154"></a>      (node.getAttribute(
<a name="line155"></a>      goog.ui.equation.ImageRenderer.EE_IMG_ATTR) ||
<a name="line156"></a>          goog.dom.classes.has(node,
<a name="line157"></a>              goog.ui.equation.ImageRenderer.EE_IMG_CLASS));
<a name="line158"></a>};
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * Returns the html for the html image tag for the given equation.
<a name="line163"></a> * @param {string} equation The equation.
<a name="line164"></a> * @return {string} The html code to embed in the document.
<a name="line165"></a> */
<a name="line166"></a>goog.ui.equation.ImageRenderer.getHtml = function(equation) {
<a name="line167"></a>  var imageSrc =
<a name="line168"></a>      goog.ui.equation.ImageRenderer.getImageUrl(equation);
<a name="line169"></a>  if (!imageSrc) {
<a name="line170"></a>    return &#39;&#39;;
<a name="line171"></a>  }
<a name="line172"></a>  return &#39;&lt;img src=&quot;&#39; + imageSrc + &#39;&quot; &#39; +
<a name="line173"></a>      &#39;alt=&quot;&#39; + goog.string.htmlEscape(equation) + &#39;&quot; &#39; +
<a name="line174"></a>      &#39;class=&quot;&#39; + goog.ui.equation.ImageRenderer.EE_IMG_CLASS +
<a name="line175"></a>      &#39; &#39; + goog.ui.equation.ImageRenderer.NO_RESIZE_IMG_CLASS +
<a name="line176"></a>      &#39;&quot; &#39; + goog.ui.equation.ImageRenderer.EE_IMG_ATTR + &#39;=&quot;1&quot; &#39; +
<a name="line177"></a>      &#39;style=&quot;vertical-align: &#39; +
<a name="line178"></a>      goog.ui.equation.ImageRenderer.EE_IMG_VERTICAL_ALIGN + &#39;&quot;&gt;&#39;;
<a name="line179"></a>};
<a name="line180"></a>
<a name="line181"></a>
<a name="line182"></a>/**
<a name="line183"></a> * Checks whether equation is too long to be displayed.
<a name="line184"></a> * @param {string} equation The equation to test.
<a name="line185"></a> * @return {boolean} Whether the equation is too long.
<a name="line186"></a> */
<a name="line187"></a>goog.ui.equation.ImageRenderer.isEquationTooLong = function(equation) {
<a name="line188"></a>  return equation.length &gt;
<a name="line189"></a>      goog.ui.equation.ImageRenderer.MAX_EQUATION_LENGTH;
<a name="line190"></a>};
</pre>


</body>
</html>
